﻿@{
    ViewBag.Title = "UserIndex";
}
@section head
{
    <link href="@Url.Content("~/ScriptPlugin/easyui/themes/gray/easyui.css")" rel="stylesheet" />
    <link href="@Url.Content("~/ScriptPlugin/easyui/themes/icon.css")" rel="stylesheet" />
    <script type="text/javascript" src="@Url.Content("~/ScriptPlugin/easyui/jquery.easyui.min.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/ScriptPlugin/easyui/locale/easyui-lang-zh_CN.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/Scripts/KingsSharp.DataGrid.Filter.js")"></script>
<script src="@Url.Content("~/ScriptPlugin/WdatePicker/js/WdatePicker.js")"></script>
}
<div id="grid">
    <div id="toolpannel">
        <div class="content-pannel-buttons">
            <a><b class="p-icon-reload">刷新 </b></a><a onclick="UserInfoAdd()">
                <b class="p-icon-add">
                    新增
                </b>
            </a><a onclick="UserInfoEdit()"><b class="p-icon-edit">编辑</b></a>
            <a onclick="UserInfoDelete()"><b class="p-icon-delete">删除</b></a>
            <a onclick="$('#grid').datagrid('load')">
                <b class="p-icon-serch">查询</b>
            </a>
        </div>
        <div class="datagrid-filter-pannel" id="filterpannel">
            <table class="content-table-serch">
                <tr>
                    <th>
                        用户名称
                    </th>
                    <td>
                        <input type="text" name="Name" data-filter="true" />
                        <a class="p-icon-filter p-icon-filter-style" style="display: block; width: 22px;
                            height: 22px; float: left">@Html.GetFilterItem("Name", typeof(string))</a>
                        </td>
                        <th>
                            性别
                        </th>
                        <td>
                            <select id="Sex" name="Sex" data-filter="true">
                                <option value="">全部</option>
                                <option value="男">男</option>
                                <option value="女">女</option>
                            </select>
                            <a class="p-icon-filter p-icon-filter-style" style="display: block; width: 22px;
                            height: 22px; float: left">@Html.GetFilterItem("Sex", typeof(bool))</a>
                        </td>
                        <th>
                            年龄从
                        </th>
                        <td>
                            <input type="text" value="0" name="Age" data-filter="true" />
                            <a class="p-icon-filter p-icon-filter-style" style="display: block; width: 22px;
                            height: 22px; float: left">@Html.GetFilterItem("Age", typeof(int),KingsSharp.Common.Filter.FilterOperate.GreaterOrEqual)</a>
                        </td>
                        <th>
                            到
                        </th>
                        <td>
                            <input type="text" value="100" name="Age" data-traget="Age1" data-filter="true" />
                            <a class="p-icon-filter p-icon-filter-style" style="display: block; width: 22px;
                            height: 22px; float: left">@Html.GetFilterItem("Age1", typeof(int), KingsSharp.Common.Filter.FilterOperate.LessOrEqual)</a>
                        </td>
                    </tr>
                <tr>
                    <th>登录帐号</th>
                    <td>
                        <input type="text" name="LoginCode" data-filter="true" />
                        <a class="p-icon-filter p-icon-filter-style" style="display: block; width: 22px;
                            height: 22px; float: left">@Html.GetFilterItem("LoginCode", typeof(string))</a>
                    </td>
                    <th>
                        最后登录时间从
                    </th>
                    <td>
                        <input type="text" class="p-icon-right p-icon-date-long" name="LastLoginDate" data-filter="true" />
                        <a class="p-icon-filter p-icon-filter-style" style="display: block; width: 22px;
                            height: 22px; float: left">@Html.GetFilterItem("LastLoginDate", typeof(DateTime), KingsSharp.Common.Filter.FilterOperate.GreaterOrEqual)</a>
                    </td>
                    <th>到</th>
                    <td>
                        <input type="text" class="p-icon-right p-icon-date-long" name="LastLoginDate" data-traget="LastLoginDate1" data-filter="true" />
                        <a class="p-icon-filter p-icon-filter-style" style="display: block; width: 22px;
                            height: 22px; float: left">@Html.GetFilterItem("LastLoginDate1", typeof(DateTime), KingsSharp.Common.Filter.FilterOperate.LessOrEqual)</a>
                    </td>
                    <th></th>
                    <td></td>
                </tr>
                </table>
            </div>
        </div>
    </div>
@section foot{
<script type="text/javascript">
    function LoadUserInfoData()
    {
        var columns = [[
                { field: "Name", title: "用户名称",width:130},
                { field: "LoginCode", title: "登录帐号", width: 130 },
                { field: "Sex", title: "性别", width: 40 },
                { field: "Age", title: "年龄", width: 40 },
                { field: "Birthday", title: "生日", width: 80 },
                { field: "Phone", title: "手机", width: 90 },
                { field: "LastLoginDate", title: "最后登录时间", width: 120 },
                { field: "LastLoginIp", title: "最后登录Ip", width: 80 },
                { field: "Browser", title: "最后使用浏览器" }
            ]];
            var parameter = {
            title: "@Html.GetGridTitle("系统管理","用户信息管理")",
            columns: columns,
            url: "@Url.Content("~/Sys/User/GetUserInfoGridData")",
            pageNumber: 1
        };
        var grid = K.GetGridData("#grid", parameter).Grid;
    }
    LoadUserInfoData();

    function UserInfoAdd()
    {
        K.layer.iframe({
            title: "@Html.GetLayerTitle(LayerIcon.Add,"新增用户")",
            content: "@Url.Content("~/Sys/User/UserAdd")",
            maxmin: true,
            initfull: true,
            btn:["保存","返回"],
            callback:function(result)
            {
                if (K.ShowOrAlert(result))
                {
                    $("#grid").datagrid("load");
                }
            }
        });
    }
    function UserInfoEdit(userid)
    {
        var row = $("#grid").datagrid("getSelected");
        if (row == null)
        {
            K.Alert("请选择需编辑的行");
            return false;
        }
        K.layer.iframe({
            title: "@Html.GetLayerTitle(LayerIcon.Edit,"编辑用户")",
            content: "@Url.Content("~/Sys/User/UserEdit")?UserId=" + row.Id,
            maxmin: true,
            initfull: true,
            btn: ["保存", "返回"],
            callback: function (result) {
                if (K.ShowOrAlert(result)) {
                    $("#grid").datagrid("load");
                }
            }
        });
    }
    function UserInfoDelete()
    {
        var row = $("#grid").datagrid("getSelected");
        if (row == null) {
            K.Alert("请选择需删除的行");
            return false;
        }
        K.Confirm("确认删除用户 \"" + row.Name + "\" ？", function () {
            K.AjaxJson("@Url.Content("~/Sys/User/UserDelete")", { UserId: row.Id, UserName: row.Name }, function (result) {
                if (K.ShowOrAlert(result)) {
                    $("#grid").datagrid("load");
                }
            }, "用户 \"" + row.Name + "\"删除中...");
        });
    }
</script>    
    
}